<?PHP
// GRRLIB screenshot convertor (GRR to png)
// This file is part of the GRRLIB package for WII
// info : http://wiibrew.org/index.php?title=Homebrew_apps/GRRLIB

$file = $argv[1];
$fh = fopen($file, 'r+');
$contents = fread($fh, filesize($file));
fclose($fh);

$im = imagecreatetruecolor(640, 480);

for($y=0;$y<480;$y++){
for($x=0;$x<640*2;$x+=2){
	$R=intval(((ord($contents[$y*640*2+$x]) >> 3)*255)/31);
	$G=intval(((((ord($contents[$y*640*2+$x]) & 0x07)<< 3) | (ord($contents[$y*640*2+$x+1]) >> 5))*255)/63);
	$B=intval(((ord($contents[$y*640*2+$x+1]) & 0x1F)*255)/31);
	$rgb = imagecolorallocate($im, $R, $G, $B );
	Imagesetpixel($im, $x/2, $y, $rgb);
}
}
	imagepng($im,$file.".png");
       imagedestroy($im);

?>
